home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / MP_PluralHeap.h < prev    next >
Text File  |  1992-01-30  |  5KB  |  132 lines

  1. /*
  2.  *    Plurals
  3.  *
  4.  *    Author:    S.C.Merrall
  5.  *
  6.  *    File:   MP_PluralHeap.c
  7.  *
  8.  *    Contents:    
  9.  *
  10.  *    Description:    This object gives a better handle on the content of the
  11.  *                      heap space. At this time I see no need to create
  12.  *                      anything other than dynamic instances of this class
  13.  *                      so none of the supporting code is present
  14.  *
  15.  *    Change History:
  16.  *
  17.  *    Date   Name Comment
  18.  *    -------- ---- -------
  19.  *    19:04:91 SCM  Created
  20.  *    22:04:91 SCM  Offset now offsets, pointer to plural of naturals
  21.  *    27:05:91 SCM  MP_PluralHeap no longer a true object
  22.  *    04:06:91 SCM  Converted header to 16 bits
  23.  *    29:01:92 SCM  Added macros for storing forwarding addresses in headers
  24.  *
  25.  */
  26.  
  27. /*     At this moment I am loathe to start creating pplural instances of
  28.  *  objects or plural objects. Ideally I would have singular objects with
  29.  *  plural things inside them. I can't do this without initialisation 
  30.  *  code. This would mean I would no longer be able to create them on the
  31.  *  stck. So I will discard them as objects and resort to the folloeing
  32.  *  typedef.
  33.  */
  34.  
  35. typedef plural natural *plural MP_PluralHeap;
  36.  
  37. /*  typedef int heap_header;
  38.  *  
  39.  *  #define HH_FREE 0x8000
  40.  *  #define HH_INFO 0x7FFF
  41.  *  #define HH_SPACE 0xFFFF0000
  42.  *  
  43.  *  #define HH_space(HEADER) (HEADER >> 16)
  44.  *  #define HH_free(HEADER) ((HEADER & HH_FREE) == H_FREE)
  45.  *  #define HH_info(HEADER) (HEADER & HH_INFO)
  46.  *  #define HH_set_space(HEADER,VALUE) (HEADER = (VALUE << 16) | \
  47.  *                      (HEADER & ~HH_SPACE))
  48.  *  #define HH_set_free(HEADER,VALUE) (HEADER = HEADER | (VALUE << 15))
  49.  *  #define HH_set_info(HEADER,VALUE) (HEADER = (VALUE | (HEADER & ~HH_INFO)))
  50.  *  
  51.  */
  52.  
  53. typedef natural heap_header;
  54.  
  55. /*  #define HH_FREE 0x0010
  56.  *  #define HH_INFO 0x000F
  57.  *  #define HH_SPACE 0xFFE0
  58.  *  
  59.  *  #define HH_space(HEADER) (HEADER >> 5)
  60.  *  #define HH_free(HEADER)  ((HEADER & HH_FREE) == H_FREE)
  61.  *  #define HH_info(HEADER)  (HEADER & HH_INFO)
  62.  *  #define HH_set_space(HEADER,VALUE) (HEADER = (VALUE << 5) | \
  63.  *                  (HEADER & ~HH_SPACE))
  64.  *  #define HH_set_free(HEADER,VALUE) (HEADER = HEADER | (VALUE << 4))
  65.  *  #define HH_set_info(HEADER,VALUE) (HEADER = (VALUE | (HEADER & ~HH_INFO)))
  66.  */
  67.  
  68. /*  In this version, free and info have been swapped around. Thus if it is free there is
  69.  *  a 15-bit space we can store the forwarding address in!
  70.  */
  71.  
  72. #define HH_FREE  0x0001
  73. #define HH_GCTO  0xFFFE
  74. #define HH_INFO  0x001E
  75. #define HH_SPACE 0xFFE0
  76.  
  77. #define HH_space(HEADER)  (HEADER >> 5)
  78. #define HH_gcto(HEADER)   (HEADER >> 1)
  79. #define HH_free(HEADER)   (HEADER & HH_FREE)
  80. #define HH_gced_p(HEADER) (HEADER & HH_FREE)
  81. #define HH_info(HEADER)   ((HEADER & HH_INFO) >> 1)
  82.  
  83. #define HH_set_space(HEADER,VALUE) HEADER = (VALUE << 5) | (HEADER & ~HH_SPACE)
  84. #define HH_set_free(HEADER,VALUE)  HEADER = (HEADER & ~HH_FREE) | (VALUE & HH_FREE)
  85. #define HH_gced(HEADER)            HEADER = HEADER | HH_FREE
  86. #define HH_set_info(HEADER,VALUE)  HEADER = ((VALUE << 1) & HH_INFO) | (HEADER & ~HH_INFO)
  87. #define HH_set_gcto(HEADER,VALUE)  HEADER = (VALUE << 1) | (HEADER & ~HH_GCTO)
  88.  
  89. #define HH_gc_moved(HEADER,TO)     HEADER = (TO << 1) | HH_FREE
  90.  
  91. #define OA_to_offsets(MPPH) (MPPH)
  92. #define OA_offsets(MPPH) (*MPPH)
  93.  
  94. #define OA_free(MPPH) (HH_free(heap_memory[*MMPH]))
  95. #define OA_info(MPPH) (HH_info(heap_memory[*MPPH]))
  96. #define OA_space(MPPH) (HH_space(heap_memory[*MPPH]))
  97. #define OA_data(MPPH) (plural char *plural) (heap_memory + (*MPPH) + 1)
  98.  
  99. #define MPP_2_MPPH(MPPH,MPP) (MPPH = &(plural_memory[MPP]))
  100. #define MPPH_2_MPP(MPP,MPPH) (plural_memory[MPP] = (*MPPH))
  101.  
  102. /* Original Definitions for future reference */
  103. /* ======== =========== === ====== ========= */
  104.  
  105. /*  extern struct MP_PluralHeap OC_MP_PluralHeap;
  106.  *  extern struct MP_PluralHeap DOC_MP_PluralHeap;
  107.  *
  108.  *  #ifdef OD_OBJECT_CHECK
  109.  *  
  110.  *  #define OA_to_offsets(OBJECT) (error(OBJECT,"OA_to_offsets",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets)
  111.  *  #define OA_offsets(OBJECT) (*null(error(OBJECT,"OA_offsets",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets))
  112.  *  #define OA_free(OBJECT) (heap_memory[*null(error(OBJECT,"OA_free",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets)].free)
  113.  *  #define OA_space(OBJECT) (heap_memory[*null(error(OBJECT,"OA_space",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets)].space)
  114.  *  #define OA_info(OBJECT) (heap_memory[*null(error(OBJECT,"OA_info",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets)].info)
  115.  *  #define OA_data(OBJECT) (plural char *plural) (heap_memory + *null(error(OBJECT,"OA_data",OI_MP_PluralHeap)->MP_PluralHeap.to_offsets) + 1)
  116.  *  
  117.  *  #else
  118.  *  
  119.  *  #define OA_to_offsets(OBJECT) (OBJECT->MP_PluralHeap.to_offsets)
  120.  *  #define OA_offsets(OBJECT) (*(OBJECT->MP_PluralHeap.to_offset))
  121.  *  #define OA_free(OBJECT) (heap_memory[*(OBJECT->MP_PluralHeap.to_offsets)].free)
  122.  *  #define OA_space(OBJECT) (heap_memory[*(OBJECT->MP_PluralHeap.to_offsets)].space)
  123.  *  #define OA_info(OBJECT) (heap_memory[*(OBJECT->MP_PluralHeap.to_offsets)].info)
  124.  *  #define OA_data(OBJECT) (plural char *plural)(heap_memory + *(OBJECT->MP_PluralHeap.to_offsets) + 1)
  125.  *  
  126.  *  #endif
  127.  *  
  128.  *  #define MPP_2_MPPH(MPPH,MPP) (OA_to_offsets(MPPH) = &(plural_memory[OA_offset(MPP)]))
  129.  *  #define MPPH_2_MPP(MPP,MPPH) (plural_memory[OA_offset(MPP)]=OA_offsets(MPPH))
  130.  *  
  131.  */  
  132.